﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Xml.Serialization;
using System.Xml.Linq;

namespace Facebook.Configuration
{
    public static class FeedTemplates
    {
        public static List<FeedTemplateElement> Get()
        {
            var config = FacebookSection.Current;
            if (String.IsNullOrEmpty(config.FeedTemplateConfigSource) ||
                !File.Exists(Environment.CurrentDirectory + config.FeedTemplateConfigSource)) return new List<FeedTemplateElement>();
            else
            {
                var serializer = new XmlSerializer(typeof(List<FeedTemplateElement>));
                var result = serializer.Deserialize(XDocument.Load(Path.Combine(Environment.CurrentDirectory, config.FeedTemplateConfigSource)).CreateReader());
                return (List<FeedTemplateElement>)result;
            }
        }
    }
}